using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The ParentStatusCodeTableManager class is responsible for managing BO.ParentStatusCodeTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class ParentStatusCodeTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all ParentStatusCodeTable objects in the database.
        /// </summary>
        /// <returns>A list with all ParentStatusCodeTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static ParentStatusCodeTableList GetList()
        {
            return ParentStatusCodeTableDB.GetList();
        }

        /// <summary>
        /// Gets a single ParentStatusCodeTable from the database without its data.
        /// </summary>
        /// <param name="parentStatusCode">The ParentStatusCode of the ParentStatusCodeTable in the database.</param>
        /// <returns>A ParentStatusCodeTable object when the ParentStatusCode exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static ParentStatusCodeTable GetItem(short parentStatusCode)
        {
            return GetItem(parentStatusCode, false);
        }

        /// <summary>
        /// Gets a single ParentStatusCodeTable from the database.
        /// </summary>
        /// <param name="parentStatusCode">The ParentStatusCode of the ParentStatusCodeTable in the database.</param>
        /// <param name="getParentStatusCodeTableRecords">Determines whether to load all associated ParentStatusCodeTable records as well.</param>
        /// <returns>
        /// A ParentStatusCodeTable object when the ParentStatusCode exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static ParentStatusCodeTable GetItem(short parentStatusCode, bool getParentStatusCodeTableRecords)
        {
            ParentStatusCodeTable myParentStatusCodeTable = ParentStatusCodeTableDB.GetItem(parentStatusCode);
            return myParentStatusCodeTable;
        }

        /// <summary>
        /// Saves a ParentStatusCodeTable in the database.
        /// </summary>
        /// <param name="myParentStatusCodeTable">The ParentStatusCodeTable instance to save.</param>
        /// <returns>The new ParentStatusCode if the ParentStatusCodeTable is new in the database or the existing ParentStatusCode when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static short Save(ParentStatusCodeTable myParentStatusCodeTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                short parentStatusCodeTableParentStatusCode = (short)ParentStatusCodeTableDB.Save(myParentStatusCodeTable);

                //  Assign the ParentStatusCodeTable its new (or existing ParentStatusCode).
                myParentStatusCodeTable.ParentStatusCode = parentStatusCodeTableParentStatusCode;

                myTransactionScope.Complete();

                return parentStatusCodeTableParentStatusCode;
            }
        }

        /// <summary>
        /// Deletes a ParentStatusCodeTable from the database.
        /// </summary>
        /// <param name="myParentStatusCodeTable">The ParentStatusCodeTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(ParentStatusCodeTable myParentStatusCodeTable)
        {
            return ParentStatusCodeTableDB.Delete(myParentStatusCodeTable.ParentStatusCode);
        }

        #endregion

    }

}
